#include "Debug.h"
#include <iostream>
#include <sstream>

bool Debug::init()
{
	
	return true;
}

void Debug::drawGrid(sf::RenderWindow& window, int dimX, int dimY)
{
	sf::Vector2u windowSize = window.getSize();

	int rows = windowSize.y / dimY;
	int cols = windowSize.x / dimY;

	sf::VertexArray xlinesToDraw;
	sf::VertexArray ylinesToDraw;

	xlinesToDraw.resize(cols * 2);
	xlinesToDraw.setPrimitiveType(sf::PrimitiveType::Lines);

	ylinesToDraw.resize(rows * 2);
	ylinesToDraw.setPrimitiveType(sf::PrimitiveType::Lines);

	int i = 0;

	for(int x = 0; x < cols; x++)
	{
		xlinesToDraw[i].position = sf::Vector2f(x * dimX, 0); xlinesToDraw[i].color = sf::Color::Color(0, 100, 100, 150);
		xlinesToDraw[i + 1].position = sf::Vector2f(x * dimX, windowSize.y); xlinesToDraw[i + 1].color = sf::Color::Color(0, 100, 100, 150);
		i += 2;
	}

	
	i = 0;
	for(int y = 0; y < rows; y++)
	{
		ylinesToDraw[i].position = sf::Vector2f(0, y * dimY); ylinesToDraw[i].color = sf::Color::Color(0, 100, 100, 150);
		ylinesToDraw[i + 1].position = sf::Vector2f(windowSize.x, y * dimY); ylinesToDraw[i + 1].color = sf::Color::Color(0, 100, 100, 150);
		i += 2;
	}

	window.draw(xlinesToDraw);
	window.draw(ylinesToDraw);

}

void Debug::drawDebug(sf::RenderWindow& window, float FPS, int numOfObjects, bool staticDrop, bool dynamicDrop)
{
	// Font needs to be replaced with a NONDEFAULT font
	// Causes video card to crash during debug on ATI cards
	sf::Text debugText;
	debugText = sf::Text("------Debug------ ");
	debugText.setScale(.5f, .5f);
	debugText.setPosition(10, 50);

	sf::Text objectsText;
	objectsText = sf::Text("Objects: ");
	objectsText.setScale(.5f, .5f);
	objectsText.setPosition(20, 70);

	sf::Text numText;
	std::stringstream ss;
	ss << numOfObjects;
	numText = sf::Text(ss.str().c_str());
	numText.setScale(.5f, .5f);
	numText.setPosition(80, 70);

	sf::Text dropTypeText;
	dropTypeText = sf::Text("Drop Type: ");
	dropTypeText.setScale(.5f, .5f);
	dropTypeText.setPosition(20, 90);

	sf::Text dropText;
	if(staticDrop)
		dropText = sf::Text("TYPE_STATIC");
	if(dynamicDrop)
		dropText = sf::Text("TYPE_DYNAMIC");
	dropText.setScale(.5f, .5f);
	dropText.setPosition(100, 90);
	
	window.draw(debugText);
	window.draw(objectsText); window.draw(numText);
	window.draw(dropTypeText); window.draw(dropText);
}